/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.api;

import org.proteusframework.api.model.IQualifiedName;
import org.proteusframework.api.model.NoSuchQualifiedNameException;
import org.proteusframework.spi.IProteusRegistrarFactory;

import java.util.Collection;

/**
 * Factory registrars maintain the authoritative runtime registration database of plugin archetypes.
 *
 * @author Tacoma Four
 */
public interface IFactoryRegistrar extends IDelegateConsumer
{
    /**
     * Creates a plugin registrar for the given qualified name representing a singular plugin archetype.
     *
     * @param qualifiedName Plugin archetype qualified name
     * @return Plugin registrar capable of creating specific plugin instances at a specific level of API version
     *         compatibility
     */
    IPluginRegistrar createRegistrar(IQualifiedName qualifiedName) throws NoSuchQualifiedNameException;

    /**
     * Lists all automatically and manually registered {@link IProteusRegistrarFactory} instances.
     *
     * @return Immutable collection of Proteus Registrar Factory instances. Any modifications to this collection have
     *         no impact on the authoritative collection maintained by this registrar.
     */
    Collection<IProteusRegistrarFactory> listFactories();

    /**
     * Determines if a factory is registered under the given qualified name.
     *
     * @param qualifiedName Qualified name to try and locate a factory under
     * @return true, if the factory is registered
     */
    boolean isInstalled(IQualifiedName qualifiedName);

    /**
     * Provides dynamic {@link IProteusRegistrarFactory} registration for those factories not formally declared
     * according to the Java SPI architecture.
     *
     * @param registrarFactory Proteus Registrar Factory instance to manually register
     */
    void addRegistrar(IProteusRegistrarFactory registrarFactory);
}
